import smtplib
from email.mime.text import MIMEText
from email.header import Header

class SendEmails:
    def __init__(self,server='smtp.qq.com',port=465,username='1503735342@qq.com',password='apgwhbbeufblgghd'):
        self.__server = server
        self.__port = port
        self.__username = username
        self.__password = password
    def send_HTML(self,from_email,to_email,subject,content):
        print(from_email,to_email,subject,content)
        msg = MIMEText(content, 'html', 'utf-8')
        msg['From'] = Header(from_email)
        msg['To'] = Header(to_email)
        msg['Subject'] = Header(subject)
        try:
            smtpObj = smtplib.SMTP_SSL(self.__server, self.__port)
            smtpObj.login(self.__username, self.__password)
            smtpObj.sendmail(from_email, to_email, msg.as_string())
            print('email send success')
        except smtplib.SMTPException as e:
            print('email send failed')
            print(e)
f_name='1503735342@qq.com'
message='<h1>123</h1>'
se=SendEmails()
se.send_HTML(f_name,f_name,'test',message)
